/********************************************************************************
 *      Copyright:  (C) 2025 ZYT
 *                  All rights reserved.
 *
 *       Filename:  main.h
 *    Description:  This file 
 *
 *        Version:  1.0.0(10/08/25)
 *         Author:  ZYT <zhangyuting@163.com>
 *      ChangeLog:  1, Release initial version on "10/08/25 09:12:09"
 *                 
 ********************************************************************************/
#ifndef MAIN_H
#define MAIN_H

#include <pthread.h>
#include <linux/can.h>
#include <stdio.h>
#include <errno.h>

// 从 common.h 内容合并而来
#ifndef CAN_BUFFER_SIZE
#define CAN_BUFFER_SIZE   64
#endif

#ifndef CAN_DEVICE
#define CAN_DEVICE        "can0"
#endif

// J1939 工具宏
#define J1939_PGN(x)      (((x) & 0x3FFFF) << 8)
#define J1939_ADDR(x)     ((x) & 0xFF)
#define J1939_PRIORITY    6

static inline __u32 j1939_can_id(__u8 priority, __u32 pgn, __u8 addr) 
{
	return (priority << 26) | (0 << 25) | (0 << 24) | (pgn & 0x3FFFF00) | (addr & 0xFF);
}

static inline __u32 get_pgn_from_can_id(__u32 can_id) 
{
	return (can_id & 0x3FFFF00) >> 8;
}

static inline __u8 get_addr_from_can_id(__u32 can_id) 
{
	return can_id & 0xFF;
}

#endif // MAIN_H

